<template>
	<view>
		<u-form :model="form" ref="uForm" :rules="rules" class="from">
			<u-form-item labelWidth="120" label="手机号" prop="phonenumber">
				<u-input placeholder="请输入手机号" v-model="form.phonenumber" />
			</u-form-item>
			<u-form-item labelWidth="80" label="密码" prop="password">
				<u-input placeholder="请输入密码" v-model="form.password" />
			</u-form-item>
		</u-form>
		<u-toast ref="uToast"></u-toast>
		<u-button @click="submit" type="primary">提交</u-button>


	</view>
</template>

<script>
	import {
		register
	} from '@/api/login.js'
	export default {
		data() {
			return {
				form: {
					phonenumber: '',
					password: '',
				},
				rules: {
					phonenumber: [{
						required: true,
						message: '请输入手机号',
						trigger: ['blur', 'change']
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}],
				}
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate().then(validated => {
					if(!validated){
						return
					}
					register(this.form).then(res2 => {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					})
				}).catch(errors => {})
			}
		},
	};
</script>
<style>
	.from {
		margin: 10px 15px;
	}
</style>
